package org.example.ndarray.operation;

import ai.djl.ndarray.NDArray;
import ai.djl.ndarray.NDManager;

public class Example1 {
    public static void main(String[] args) {
        try (NDManager ndManager = NDManager.newBaseManager()) {
            /*
               NDArray 支持大量的运算符（operator）
               比如说我们可以对之前创建的两个形状为(3, 4)的NDArray做按元素加法，所得结果形状不变
               在接下来的例子中，我们构建两个一维NDArray，对它们进行六种基本运算
             */
            NDArray x = ndManager.create(new float[]{1f, 2f, 4f, 8f});
            NDArray y = ndManager.create(new float[]{2f, 2f, 2f, 2f});
            System.out.println("x = " + x);
            System.out.println("y = " + y);
            System.out.println("x + y = " + x.add(y));
            System.out.println("x - y = " + x.sub(y));
            System.out.println("x * y = " + x.mul(y));
            System.out.println("x / y = " + x.div(y));
            System.out.println("x ** y = " + x.pow(y));
            System.out.println("e ** x = " + x.exp());
        }
    }
}
